import java.util.Stack;
/*
 * @author zzr
 * @date: 2025/10/14  10:43
 * @description: 将递归转换为循环
 */
public class Demo15 {
    public void reversePrintList(Demo3.ListNode head) {

        Stack<Demo3.ListNode> stack = new Stack<>();
        Demo3.ListNode cur = head;

        while (cur != null) {
            stack.push(cur);
            cur= cur.next;
        }
        while (!stack.isEmpty()) {
            Demo3.ListNode top = stack.pop();
            System.out.println(top.val + " ");
        }
        System.out.println();
    }
}
